package serverlogic;

import java.util.Iterator;
import java.util.Map.Entry;

import net.com.sunkey.protobuf.PluginRequest.PluginRequestData;
import net.com.sunkey.protobuf.PropertyData.Property;
import net.com.sunkey.serverlogic.Plugin;
import net.com.sunkey.serverlogic.PluginData;
import net.com.sunkey.serverlogic.Room;
import net.com.sunkey.serverlogic.User;

/**
 * @author kohachiro
 *
 */
public class PluginDemo extends Plugin {

	/**
	 * 
	 */
	public PluginDemo() {
		// TODO Auto-generated constructor stub
	}
	public PluginData Roomlist(PluginRequestData data, User user) {
		PluginData message=new PluginData(register(),data.getAction());
		message.addProperty("argv1", "PRC");
		message.addProperty("argv2", "CALL");
		message.addProperty("argv3", "OK");		
		return message;
	}
	/* (non-Javadoc)
	 * @see net.com.sunkey.serverlogic.Plugin#invoke(java.lang.Object, java.lang.Object)
	 */
	@Override
	public PluginData invoke(PluginRequestData data, User user) throws Exception {
		PluginData message=new PluginData(register(),data.getAction());
		if (data.getAction().equals("Roomlist")){
			Property property=data.getProperty(0);
			System.out.println(property.getName()+","+property.getValue());
			
			for (Iterator<?> it=user.getRoom().getZone().getRoomList().entrySet().iterator();it.hasNext();){
				Room room=(Room)((Entry<?, ?>)it.next()).getValue();
				message.addProperty(String.valueOf(room.getId()), room.toString());
			}
		}
		return message;
	}

	/* (non-Javadoc)
	 * @see net.com.sunkey.serverlogic.Plugin#register()
	 */
	@Override
	public String register() {
		return "PluginDemo";
	}
}
